import { Body, Controller, Post } from "@nestjs/common";
import { CreateLog, Roles } from "@/common/decorators";
import { Role } from "@/common/enum/role.enum";
import { SysPermission } from "@/database/entity/SysPermission";
import { CreatePermDto } from "./dto/create-perm.dto";
import { UpdatePermDto } from "./dto/update-perm.dto";
import { PermService } from "./perm.service";

@Controller("sys/permission")
export class PermController {
    constructor(private readonly permService: PermService) {}

    /** 新增系统权限 */
    @CreateLog({ module: "系统菜单", type: "create", action: "创建系统权限" }, SysPermission)
    @Roles(Role.SUPER_ADMIN)
    @Post("create")
    async create(@Body() perm: CreatePermDto) {
        return this.permService.create(perm);
    }

    /** 删除系统权限 */
    @CreateLog({ module: "系统菜单", type: "delete", action: "删除系统权限" }, SysPermission)
    @Roles(Role.SUPER_ADMIN)
    @Post("remove")
    async remove(@Body("id") id: string) {
        return this.permService.remove(id);
    }

    /** 更新系统权限 */
    @CreateLog({ module: "系统菜单", type: "update", action: "更新系统权限" }, SysPermission)
    @Roles(Role.SUPER_ADMIN)
    @Post("update")
    async update(@Body() perm: UpdatePermDto) {
        return this.permService.update(perm);
    }
}
